.class public Lcom/glympse/platform/common/TwitterJobs$PostJob;
.super Lcom/glympse/platform/common/OAuthJob;
.source "TwitterJobs.java"


# annotations
.annotation system Ldalvik/annotation/EnclosingClass;
    value = Lcom/glympse/platform/common/TwitterJobs;
.end annotation

.annotation system Ldalvik/annotation/InnerClass;
    accessFlags = 0x9
    name = "PostJob"
.end annotation


# instance fields
.field private m_oRecipient:Lcom/glympse/platform/common/Recipient;


# direct methods
.method public constructor <init>(Lcom/glympse/platform/common/Recipient;Ljava/lang/String;)V
    .locals 8
    .parameter "oRecipient"
    .parameter "strMessage"

    .prologue
    const/4 v0, 0x1

    .line 173
    invoke-direct {p0}, Lcom/glympse/platform/common/OAuthJob;-><init>()V

    .line 175
    iput-boolean v0, p0, Lcom/glympse/platform/common/TwitterJobs$PostJob;->m_fCompleteOnMainThread:Z

    .line 176
    iput-boolean v0, p0, Lcom/glympse/platform/common/TwitterJobs$PostJob;->m_fReadResponseForFailedCall:Z

    .line 178
    iput-object p1, p0, Lcom/glympse/platform/common/TwitterJobs$PostJob;->m_oRecipient:Lcom/glympse/platform/common/Recipient;

    .line 180
    new-instance v7, Lcom/glympse/platform/GVector$NameValueNodes;

    invoke-direct {v7}, Lcom/glympse/platform/GVector$NameValueNodes;-><init>()V

    .line 183
    .local v7, listParams:Lcom/glympse/platform/GVector$NameValueNodes;,"Lcom/glympse/platform/GVector$NameValueNodes;"
    invoke-static {}, Lcom/glympse/platform/Platform;->instance()Lcom/glympse/platform/Platform;

    move-result-object v0

    iget-object v0, v0, Lcom/glympse/platform/Platform;->m_oConfig:Lcom/glympse/platform/Config;

    iget-boolean v0, v0, Lcom/glympse/platform/Config;->m_fShareMyLocation:Z

    if-eqz v0, :cond_0

    .line 184
    invoke-static {}, Lcom/glympse/platform/Platform;->instance()Lcom/glympse/platform/Platform;

    move-result-object v0

    iget-object v0, v0, Lcom/glympse/platform/Platform;->m_oLocManager:Lcom/glympse/platform/LocManager;

    iget-object v0, v0, Lcom/glympse/platform/LocManager;->m_oLastLocPoint:Lcom/glympse/platform/common/LocPoint;

    invoke-virtual {v0}, Lcom/glympse/platform/common/LocPoint;->HasLocation()Z

    move-result v0

    if-eqz v0, :cond_0

    .line 186
    new-instance v0, Lcom/glympse/platform/common/NameValueNode;

    const-string v1, "lat"

    invoke-static {}, Lcom/glympse/platform/Platform;->instance()Lcom/glympse/platform/Platform;

    move-result-object v2

    iget-object v2, v2, Lcom/glympse/platform/Platform;->m_oLocManager:Lcom/glympse/platform/LocManager;

    iget-object v2, v2, Lcom/glympse/platform/LocManager;->m_oLastLocPoint:Lcom/glympse/platform/common/LocPoint;

    iget-wide v2, v2, Lcom/glympse/platform/common/LocPoint;->m_dLatitude:D

    invoke-static {v2, v3}, Ljava/lang/Double;->toString(D)Ljava/lang/String;

    move-result-object v2

    invoke-direct {v0, v1, v2}, Lcom/glympse/platform/common/NameValueNode;-><init>(Ljava/lang/String;Ljava/lang/String;)V

    invoke-virtual {v7, v0}, Lcom/glympse/platform/GVector$NameValueNodes;->addElement(Ljava/lang/Object;)V

    .line 187
    new-instance v0, Lcom/glympse/platform/common/NameValueNode;

    const-string v1, "long"

    invoke-static {}, Lcom/glympse/platform/Platform;->instance()Lcom/glympse/platform/Platform;

    move-result-object v2

    iget-object v2, v2, Lcom/glympse/platform/Platform;->m_oLocManager:Lcom/glympse/platform/LocManager;

    iget-object v2, v2, Lcom/glympse/platform/LocManager;->m_oLastLocPoint:Lcom/glympse/platform/common/LocPoint;

    iget-wide v2, v2, Lcom/glympse/platform/common/LocPoint;->m_dLongitude:D

    invoke-static {v2, v3}, Ljava/lang/Double;->toString(D)Ljava/lang/String;

    move-result-object v2

    invoke-direct {v0, v1, v2}, Lcom/glympse/platform/common/NameValueNode;-><init>(Ljava/lang/String;Ljava/lang/String;)V

    invoke-virtual {v7, v0}, Lcom/glympse/platform/GVector$NameValueNodes;->addElement(Ljava/lang/Object;)V

    .line 191
    :cond_0
    new-instance v0, Lcom/glympse/platform/common/NameValueNode;

    const-string v1, "status"

    invoke-direct {v0, v1, p2}, Lcom/glympse/platform/common/NameValueNode;-><init>(Ljava/lang/String;Ljava/lang/String;)V

    invoke-virtual {v7, v0}, Lcom/glympse/platform/GVector$NameValueNodes;->addElement(Ljava/lang/Object;)V

    .line 193
    const/4 v1, 0x0

    .line 194
    const-string v2, "http://api.twitter.com/1/statuses/update.json"

    .line 195
    const-string v3, "F1yA1TIxkIrJr7O3Rz1Pvg"

    const-string v4, "eJ2CBiBQMgRqFhpGGZFmwNhnMS3lwa2uQ1BvElsCOM"

    .line 196
    invoke-static {}, Lcom/glympse/platform/Platform;->instance()Lcom/glympse/platform/Platform;

    move-result-object v0

    iget-object v0, v0, Lcom/glympse/platform/Platform;->m_oConfig:Lcom/glympse/platform/Config;

    iget-object v5, v0, Lcom/glympse/platform/Config;->m_strTwitterToken:Ljava/lang/String;

    .line 197
    invoke-static {}, Lcom/glympse/platform/Platform;->instance()Lcom/glympse/platform/Platform;

    move-result-object v0

    iget-object v0, v0, Lcom/glympse/platform/Platform;->m_oConfig:Lcom/glympse/platform/Config;

    iget-object v6, v0, Lcom/glympse/platform/Config;->m_strTwitterTokenSecret:Ljava/lang/String;

    move-object v0, p0

    .line 193
    invoke-virtual/range {v0 .. v7}, Lcom/glympse/platform/common/TwitterJobs$PostJob;->SendOAuthRequest(ZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/glympse/platform/GVector$NameValueNodes;)V

    .line 199
    return-void
.end method


# virtual methods
.method public OnComplete(Lcom/glympse/platform/common/JobQueue;)V
    .locals 7
    .parameter "oJobQueue"

    .prologue
    const/16 v6, 0x2e

    .line 205
    invoke-virtual {p0}, Lcom/glympse/platform/common/TwitterJobs$PostJob;->DumpDownload()V

    .line 208
    iget-object v3, p0, Lcom/glympse/platform/common/TwitterJobs$PostJob;->m_oRecipient:Lcom/glympse/platform/common/Recipient;

    iget-boolean v4, p0, Lcom/glympse/platform/common/TwitterJobs$PostJob;->m_fSuccess:Z

    if-eqz v4, :cond_5

    const/4 v4, 0x5

    :goto_0
    iput v4, v3, Lcom/glympse/platform/common/Recipient;->m_eSendState:I

    .line 223
    iget-boolean v3, p0, Lcom/glympse/platform/common/TwitterJobs$PostJob;->m_fSuccess:Z

    if-nez v3, :cond_4

    .line 226
    iget-object v3, p0, Lcom/glympse/platform/common/TwitterJobs$PostJob;->m_oRecipient:Lcom/glympse/platform/common/Recipient;

    iget v4, p0, Lcom/glympse/platform/common/TwitterJobs$PostJob;->m_nResultCode:I

    iput v4, v3, Lcom/glympse/platform/common/Recipient;->m_nResult:I

    .line 229
    iget-object v3, p0, Lcom/glympse/platform/common/TwitterJobs$PostJob;->m_abResponse:[B

    if-eqz v3, :cond_1

    iget-object v3, p0, Lcom/glympse/platform/common/TwitterJobs$PostJob;->m_abResponse:[B

    array-length v3, v3

    if-lez v3, :cond_1

    .line 232
    new-instance v3, Lcom/glympse/platform/common/CharArrayPointer;

    iget-object v4, p0, Lcom/glympse/platform/common/TwitterJobs$PostJob;->m_abResponse:[B

    invoke-direct {v3, v4}, Lcom/glympse/platform/common/CharArrayPointer;-><init>([B)V

    invoke-static {v3}, Lcom/glympse/platform/common/Helpers;->ParseJSON(Lcom/glympse/platform/common/CharArrayPointer;)Lcom/glympse/platform/GVector$NameValueNodes;

    move-result-object v1

    .line 233
    .local v1, listNameValues:Lcom/glympse/platform/GVector$NameValueNodes;,"Lcom/glympse/platform/GVector$NameValueNodes;"
    if-eqz v1, :cond_1

    .line 236
    invoke-virtual {v1}, Lcom/glympse/platform/GVector$NameValueNodes;->elements()Ljava/util/Enumeration;

    move-result-object v0

    .local v0, iter:Ljava/util/Enumeration;
    :cond_0
    invoke-interface {v0}, Ljava/util/Enumeration;->hasMoreElements()Z

    move-result v3

    if-nez v3, :cond_6

    .line 253
    .end local v0           #iter:Ljava/util/Enumeration;
    .end local v1           #listNameValues:Lcom/glympse/platform/GVector$NameValueNodes;,"Lcom/glympse/platform/GVector$NameValueNodes;"
    :cond_1
    :goto_1
    iget-object v3, p0, Lcom/glympse/platform/common/TwitterJobs$PostJob;->m_oRecipient:Lcom/glympse/platform/common/Recipient;

    iget-object v3, v3, Lcom/glympse/platform/common/Recipient;->m_strResult:Ljava/lang/String;

    invoke-static {v3}, Lcom/glympse/platform/common/Helpers;->IsEmpty(Ljava/lang/String;)Z

    move-result v3

    if-eqz v3, :cond_2

    .line 255
    const/16 v3, 0x191

    iget v4, p0, Lcom/glympse/platform/common/TwitterJobs$PostJob;->m_nResultCode:I

    if-ne v3, v4, :cond_7

    .line 257
    iget-object v3, p0, Lcom/glympse/platform/common/TwitterJobs$PostJob;->m_oRecipient:Lcom/glympse/platform/common/Recipient;

    const-string v4, "You are not authorized to post to Twitter."

    iput-object v4, v3, Lcom/glympse/platform/common/Recipient;->m_strResult:Ljava/lang/String;

    .line 269
    :cond_2
    :goto_2
    new-instance v3, Ljava/lang/StringBuilder;

    const-string v4, "Twitter post failed: "

    invoke-direct {v3, v4}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    iget-object v4, p0, Lcom/glympse/platform/common/TwitterJobs$PostJob;->m_oRecipient:Lcom/glympse/platform/common/Recipient;

    iget v4, v4, Lcom/glympse/platform/common/Recipient;->m_nResult:I

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v3

    const-string v4, ", \""

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    iget-object v4, p0, Lcom/glympse/platform/common/TwitterJobs$PostJob;->m_oRecipient:Lcom/glympse/platform/common/Recipient;

    iget-object v4, v4, Lcom/glympse/platform/common/Recipient;->m_strResult:Ljava/lang/String;

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    const-string v4, "\""

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v3

    invoke-static {v3}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/String;)V

    .line 272
    iget-object v3, p0, Lcom/glympse/platform/common/TwitterJobs$PostJob;->m_oRecipient:Lcom/glympse/platform/common/Recipient;

    iget-object v3, v3, Lcom/glympse/platform/common/Recipient;->m_strResult:Ljava/lang/String;

    iget-object v4, p0, Lcom/glympse/platform/common/TwitterJobs$PostJob;->m_oRecipient:Lcom/glympse/platform/common/Recipient;

    iget-object v4, v4, Lcom/glympse/platform/common/Recipient;->m_strResult:Ljava/lang/String;

    invoke-virtual {v4}, Ljava/lang/String;->length()I

    move-result v4

    const/4 v5, 0x1

    sub-int/2addr v4, v5

    invoke-virtual {v3, v4}, Ljava/lang/String;->charAt(I)C

    move-result v3

    if-eq v6, v3, :cond_3

    .line 274
    iget-object v3, p0, Lcom/glympse/platform/common/TwitterJobs$PostJob;->m_oRecipient:Lcom/glympse/platform/common/Recipient;

    iget-object v4, v3, Lcom/glympse/platform/common/Recipient;->m_strResult:Ljava/lang/String;

    new-instance v5, Ljava/lang/StringBuilder;

    invoke-static {v4}, Ljava/lang/String;->valueOf(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v4

    invoke-direct {v5, v4}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {v5, v6}, Ljava/lang/StringBuilder;->append(C)Ljava/lang/StringBuilder;

    move-result-object v4

    invoke-virtual {v4}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v4

    iput-object v4, v3, Lcom/glympse/platform/common/Recipient;->m_strResult:Ljava/lang/String;

    .line 278
    :cond_3
    iget-object v3, p0, Lcom/glympse/platform/common/TwitterJobs$PostJob;->m_oRecipient:Lcom/glympse/platform/common/Recipient;

    iget-object v4, v3, Lcom/glympse/platform/common/Recipient;->m_strResult:Ljava/lang/String;

    new-instance v5, Ljava/lang/StringBuilder;

    invoke-static {v4}, Ljava/lang/String;->valueOf(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v4

    invoke-direct {v5, v4}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    const-string v4, " You may need to sign out of Twitter and sign in again."

    invoke-virtual {v5, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v4

    invoke-virtual {v4}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v4

    iput-object v4, v3, Lcom/glympse/platform/common/Recipient;->m_strResult:Ljava/lang/String;

    .line 281
    :cond_4
    invoke-static {}, Lcom/glympse/platform/Platform;->instance()Lcom/glympse/platform/Platform;

    move-result-object v3

    const/16 v4, 0x1000

    invoke-virtual {v3, v4}, Lcom/glympse/platform/Platform;->DoUpdate(I)V

    .line 282
    return-void

    .line 208
    :cond_5
    const/4 v4, 0x4

    goto/16 :goto_0

    .line 238
    .restart local v0       #iter:Ljava/util/Enumeration;
    .restart local v1       #listNameValues:Lcom/glympse/platform/GVector$NameValueNodes;,"Lcom/glympse/platform/GVector$NameValueNodes;"
    :cond_6
    invoke-interface {v0}, Ljava/util/Enumeration;->nextElement()Ljava/lang/Object;

    move-result-object v2

    check-cast v2, Lcom/glympse/platform/common/NameValueNode;

    .line 241
    .local v2, oNodeCur:Lcom/glympse/platform/common/NameValueNode;
    iget-object v3, v2, Lcom/glympse/platform/common/NameValueNode;->m_strName:Ljava/lang/String;

    invoke-static {v3}, Lcom/glympse/platform/common/Helpers;->IsEmpty(Ljava/lang/String;)Z

    move-result v3

    if-nez v3, :cond_0

    iget-object v3, v2, Lcom/glympse/platform/common/NameValueNode;->m_strValue:Ljava/lang/String;

    invoke-static {v3}, Lcom/glympse/platform/common/Helpers;->IsEmpty(Ljava/lang/String;)Z

    move-result v3

    if-nez v3, :cond_0

    .line 242
    iget-object v3, v2, Lcom/glympse/platform/common/NameValueNode;->m_strName:Ljava/lang/String;

    const-string v4, "error"

    invoke-virtual {v3, v4}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z

    move-result v3

    if-eqz v3, :cond_0

    .line 245
    iget-object v3, p0, Lcom/glympse/platform/common/TwitterJobs$PostJob;->m_oRecipient:Lcom/glympse/platform/common/Recipient;

    iget-object v4, v2, Lcom/glympse/platform/common/NameValueNode;->m_strValue:Ljava/lang/String;

    iput-object v4, v3, Lcom/glympse/platform/common/Recipient;->m_strResult:Ljava/lang/String;

    goto/16 :goto_1

    .line 259
    .end local v0           #iter:Ljava/util/Enumeration;
    .end local v1           #listNameValues:Lcom/glympse/platform/GVector$NameValueNodes;,"Lcom/glympse/platform/GVector$NameValueNodes;"
    .end local v2           #oNodeCur:Lcom/glympse/platform/common/NameValueNode;
    :cond_7
    iget v3, p0, Lcom/glympse/platform/common/TwitterJobs$PostJob;->m_nResultCode:I

    if-lez v3, :cond_8

    .line 261
    iget-object v3, p0, Lcom/glympse/platform/common/TwitterJobs$PostJob;->m_oRecipient:Lcom/glympse/platform/common/Recipient;

    new-instance v4, Ljava/lang/StringBuilder;

    const-string v5, "Twitter responded with an error ("

    invoke-direct {v4, v5}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    iget v5, p0, Lcom/glympse/platform/common/TwitterJobs$PostJob;->m_nResultCode:I

    invoke-virtual {v4, v5}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v4

    const-string v5, ")."

    invoke-virtual {v4, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v4

    invoke-virtual {v4}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v4

    iput-object v4, v3, Lcom/glympse/platform/common/Recipient;->m_strResult:Ljava/lang/String;

    goto/16 :goto_2

    .line 265
    :cond_8
    iget-object v3, p0, Lcom/glympse/platform/common/TwitterJobs$PostJob;->m_oRecipient:Lcom/glympse/platform/common/Recipient;

    const-string v4, "Twitter responded with an error."

    iput-object v4, v3, Lcom/glympse/platform/common/Recipient;->m_strResult:Ljava/lang/String;

    goto/16 :goto_2
.end method
